//
//  WBNavigationController.swift
//  WSWeibo
//
//  Created by guojianfeng on 2017/7/13.
//  Copyright © 2017年 guojianfeng. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //避免融合
        navigationBar.isHidden = true
    }
    
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        if childViewControllers.count > 0{
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as? WBBaseViewController {
                var backTitle = "返回"
                if childViewControllers.count == 1 {
                    backTitle = childViewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: backTitle, target: self, action: #selector(popToParent), isBack: true)
            }
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func popToParent() {
        self.popViewController(animated: true)
    }
}

